#include "connection.hpp"
#include <iostream>
#include <string>

int main(int argc, char* argv[])
{
    if(argc != 2)
    {
        std::cout << "Usage: " << argv[0] << " count" << std::endl;
        return 0;
    }
    NS_AsyncWorker::AsyncWorker::Ptr async_worker = std::make_shared<NS_AsyncWorker::AsyncWorker>();
    NS_Connection::Connection::Ptr conn = std::make_shared<NS_Connection::Connection>("127.0.0.1", 8080, async_worker);
    NS_Channel::Channel::Ptr channel = conn->openChannel();

    google::protobuf::Map<std::string, std::string> args;
    channel->declareExchange("exchange1", NS_Message::ExchangeType::TOPIC, true, true, args);
    channel->declareMsgQueue("queue1", false, true, true, args);
    channel->declareMsgQueue("queue2", false, true, true, args);
    channel->Bind("exchange1", "queue1", "queue");
    channel->Bind("exchange1", "queue2", "news.music.#");

    NS_Message::MessageProperties mp;
    mp.set_id(NS_Helper::Uuid::uuid());
    mp.set_mode(NS_Message::DeliveryMode::DURABLE);
    // DLOG("是否持久化：%d", mp.mode() == NS_Message::DeliveryMode::DURABLE);
    // mp.set_routing_key("queue");
    int count = std::stoi(argv[1]);
    for (int i = 0; i < count; i++)
    {
        if(!conn->connected())
            break;
        mp.set_id(NS_Helper::Uuid::uuid());
    mp.set_routing_key("queue");
    channel->basicPublic("exchange1", &mp, "hello world" + std::to_string(i));
    mp.set_routing_key("news.music.pop");
    channel->basicPublic("exchange1", &mp, "hello world" + std::to_string(i));
}
    if(conn->connected())
        conn->closeChannel(channel);
    return 0;
}